/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <algorithm>


#include "../config.h"

#include "../macros.h"

int perft(Board& board, int depth) {
	int ret = 0;
	UnmakeMoveInfo unmakeInfo;
	MoveGenerator move;

	for ( move = MoveGenerator::begin(board);
		move != MoveGenerator::end(); ++move) {

		if ( 0 == depth )
			ret += 1;
		else {
			MoveMaker::make(*move, unmakeInfo, board);
			ret += perft(board, depth - 1);
			MoveMaker::unmake(unmakeInfo, board);
		}

	}

	return ret;
}

int main(int argc, const char* argv[])
{
	std::cout << "perft" << std::endl;


	Board board = Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");

	std::cout << perft(board, atoi(argv[1])) << std::endl;

}

